/*
 * @Author: Turump 
 * @Date: 2021-03-29 16:57:25 
 * @Last Modified by: Turump
 * @Last Modified time: 2021-04-27 11:46:48
 */

export default class ActionHelper {
    /*
     * 获取两点间的bezier运动
     */
    static getBezierAction(time, startPt: cc.Vec2, endPt: cc.Vec2) {
        let c1 = startPt.add(endPt.sub(startPt).div(3).add(cc.v2(0, 100)))
        let c2 = startPt.add(endPt.sub(startPt).div(3 / 2).add(cc.v2(0, 100)))
        return cc.bezierTo(time, [c1, c2, endPt]);
    }

    /**
     * 呼吸动画
     */
    static getBreathAction(time, originalScale: cc.Vec2 = cc.v2(1, 1), xScaleDelta = 0.05, yScaleDelta = 0.05) {
        return cc.tween().to(time * 0.5, { scaleX: originalScale.x * (1 + xScaleDelta), scaleY: originalScale.y * (1 - yScaleDelta) })
            .to(time * 0.5, { scaleX: originalScale.x * (1 - xScaleDelta), scaleY: originalScale.y * (1 + yScaleDelta) })
    }

    /**
     * 先放大再回原的提示动作
     */
    static getScaleTipAction() {
        return cc.tween().by(0.25, { scale: 0.1 }).by(0.25, { scale: -0.1 })
    }

    static getBounceAction(node: cc.Node) {
        return cc.tween(node)
            .to(0.15, { scaleX: node.scaleX + 0.05, scaleY: node.scaleY - 0.05 })
            .to(0.15, { scaleX: node.scaleX - 0.05, scaleY: node.scaleY + 0.05 })
            .to(0.15, { scale: node.scale })
    }
}